{
	name:"Version",
	importCommand:[{
		key:"VersionPicker",
		path:'./paint_plugin/version-mng'
	},{
		key:'{Letter,Plugin,Web}',
		path:'./config'
	},{
		key:"BaseEditMX",
		path:"./paint_tool/base-edit.mx"
	}],
	onInit(){
		this.letters = Letter.capital
		this.versionPicker = new VersionPicker(this.$event,this.$env)
		this.toolInstances = this.$env.get("toolInstances")
		this.mixin([BaseEditMX])
		this.init()
		this.bind()
	},
	bind(){
		this.on(EN.pathFocus,(ids)=>{
			this.versionPicker.focusItems(ids)
		})
		this.$version.on(EN.remove,(ids)=>{
			if(!this.active)return 
			this.versionPicker.removeItems(ids)
		})
		this.$version.on(EN.update,(step)=>{
			if(!this.active)return
			this.versionPicker.updateCache(step)
		})
		this.versionPicker.on(EN.onLeftItemFocus,this.onPathFocusByID.bind(this))
		this.versionPicker.on(EN.input_done,this.onInputDone.bind(this))
	},

	onInputDone(data,r,save){
		if(!this.active)return
		this.clearRect()
		if(data.action===Action.FunctionTool)
			this.onFuncUpdate(data,r)
		else this.onStepUpdate(data,r,save)
	},
	onStepUpdate(data,r,save){
		let {state,step,id,action} = this.$version.mergeByCommand(data,r)
		if(save)
			this.$version.commit(action,{step,state},id)
		if(state.visible)
			this.hpath({state,step})
	},
	onFuncUpdate(data,save){
		let {state,step,id,action} = data
		if(save)
			this.$version.commit(action,{step,state},id)
		if(state.visible)
			this.hpath(data)
	},
	onFocusIn(nav){
		this.$event.emit(EN.requestLeftPanel,nav.assign({id:Plugin.version}))
		this.versionPicker.focusIn(this.loadLastVersion())
	},
	onFocusOut(){
		this.ghostCtx.pathMode = false
		this.versionPicker.focusOut()
	},
	loadLastVersion(){
		return this.$version.lastVersionNoFilter().reverse()
	}
}